<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>upload模块快速使用</title>
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
</head>
<body>

<button type="button" class="layui-btn" id="test1">
    <i class="layui-icon">&#xe67c;</i>上传图片
</button>
<img id="img1">

<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        var $=layui.jquery;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/api/file/upload.do' //上传接口
            ,done: function(res){
                //上传完毕回调
                console.log(res);
                if (res.code == 200){
                    //上传成功
                    $("#img1")[0].src = res.message;
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
</body>
